import axios from "axios";

//基础配置
export const httpUtils = axios.create({
    baseURL: 'http://localhost:8080',
    timeout: 5000,
    headers: { 'Content-Type': 'application/json' }
});

//拦截器
httpUtils.interceptors.request.use(config => {
    const token = localStorage.getItem('token');
    if (token) {
        config.headers['token'] = token;
    }
    return config;
}, error => {
    return Promise.reject(error);
});


httpUtils.interceptors.response.use(response => {
    return response.data;
}, error => {
    return Promise.reject(error);
});


export default httpUtils;